package cn.lzx;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by lzx on 16/11/25.
 */
@SpringBootApplication
@Controller
public class Application {

    public static void main(String[] args) {

        SpringApplication.run(Application.class, args);
    }

    @RequestMapping(value = "/hello")
    @ResponseBody
    public void index(@RequestBody byte[] bytes) throws IOException {
        Map<String, String> map = new HashMap<>();
        //        byte[] bytes = IOUtils.toByteArray(file.getInputStream());
        System.out.println(bytes.length);
        OutputStream stream = FileUtils.openOutputStream(new File("test_copy"));
        IOUtils.write(bytes, stream);
        stream.flush();
        stream.close();

        //        map.put("title", "中国人");
        //        map.put("description", "是好人");
        //        map.put("picUrl", "http://boxfish-assets.oss-cn-hangzhou.aliyuncs
        //        .com/daily-video/video-cover/475_015452_f51a3.jpg");
        //        map.put("videoUrl", "http://boxfish-assets.oss-cn-hangzhou.aliyuncs.com/daily-video/test.mp4");
        //        ModelAndView mav = new ModelAndView();
        //        mav.addAllObjects(map);
        //        mav.setViewName("index");
        //        return mav;
    }
}
